package jgl.vajra.kingkong.part.vehicle.activity;

import java.util.Map;

import io.reactivex.Observable;
import jgl.vajra.kingkong.R;
import jgl.vajra.kingkong.bean.OwnerDetailsBean;
import jgl.vajra.kingkong.bean.OwnerOrderListBean;
import jgl.vajra.kingkong.part.vehicle.viewModel.HistoricalOrderViewModel;
import jgl.vajra.kingkong.utils.RandomUtils;
import jgl.vajra.kingkong.widget.base.BaseListActivity;
import jgl.vajra.kingkong.widget.bean.BaseListData;
import jgl.vajra.kingkong.widget.interfaces.RefreshRecyclerLoadStatusListener;
import jgl.vajra.kingkong.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.kingkong.widget.recyclerView.RefreshRecyclerNetConfig;
import jgl.vajra.kingkong.widget.retrofithelper.utils.AEACCoder;

@CreateViewModel(HistoricalOrderViewModel.class)
public class HistoricalOrderActivity extends BaseListActivity<HistoricalOrderViewModel, OwnerDetailsBean.CarListBean> {

    private String invitation;

    @Override
    protected String getToolbarTitle() {
        return "全部活";
    }

    @Override
    protected RefreshRecyclerNetConfig getRefreshRecyclerNetConfig() {
        return new RefreshRecyclerNetConfig() {
            @Override
            public Observable getNetObservable(Map<String, Object> map, int action) {
                map.put("Authorization", AEACCoder.encrypt(RandomUtils.getRandom()));
                map.put("invitation", invitation);
                return mViewModel.getHistoricalOrderList(map);
            }
        };
    }

    @Override
    protected int getItemLayout() {
        return R.layout.item_owner_details_order;
    }

    @Override
    public void onItemClick(int position, OwnerDetailsBean.CarListBean itemData) {

    }

    @Override
    public void initView() {
        super.initView();

        invitation = getIntent().getStringExtra("invitation");

        mBinding.recyclerView.setIsDataObject(true);
        mBinding.recyclerView.setRefreshLoaderMore(false, false);
        mBinding.recyclerView.setRefreshRecyclerLoadStatusListener(new RefreshRecyclerLoadStatusListener<BaseListData<OwnerOrderListBean>>() {
            @Override
            public void onSucceed(BaseListData<OwnerOrderListBean> data, int action) {
                mBinding.recyclerView.setRefreshLoaderMore(true, true);


                mBinding.recyclerView.requestNetObjectSuccess(data.data, action);
            }

            @Override
            public void onError(String errorInfo, int errorCode, int action) {
                super.onError(errorInfo, errorCode, action);
//
            }
        });
        mBinding.recyclerView.firstLoad();
    }
}
